package com.zhuss.common;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public interface BaseBo {
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	
	SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	default Date toDate(Long time) {
		if (time == null) {
			return null;
		}
		return new Date(time);
	}
	
	default Date toDate(String time) {
		if (time == null) {
			return null;
		}
		Date date = null;
		try {
			date = sdf.parse(time);
		} catch (ParseException e) {
			return null;
		}
		return date;
	}
	
	default Date toDateTime(String time) {
		if (time == null) {
			return null;
		}
		Date date = null;
		try {
			date = sdfTime.parse(time);
		} catch (ParseException e) {
			return null;
		}
		return date;
	}
	
	default Long toPrice(String price) {
		if (price == null) {
			return null;
		}
		BigDecimal bd = new BigDecimal(price);
		return (long)(bd.doubleValue() * 100);
	}

}
